<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Sales $block */

$singleStoreMode = $block->isSingleStoreMode();
?>
<div class="entry-edit fieldset-wrapper">

    <div class="fieldset-wrapper-title">
        <span class="title"><?php echo $block->escapeHtml(__('Sales Statistics')) ?></span>
    </div>

    <table class="data-table">
        <thead>
        <tr>
            <?php if (!$singleStoreMode): ?>
            <th><?php echo $block->escapeHtml(__('Web Site')) ?></th>
            <th><?php echo $block->escapeHtml(__('Store')) ?></th>
            <th><?php echo $block->escapeHtml(__('Store View')) ?></th>
            <?php endif; ?>
            <th><?php echo $block->escapeHtml(__('Lifetime Sales')) ?></th>
            <th class="last"><?php echo $block->escapeHtml(__('Average Sale')) ?></th>
        </tr>
        </thead>
        <?php if (!$singleStoreMode): ?>
        <tfoot>
        <tr>
            <td colspan="3"><strong><?php echo $block->escapeHtml(__('All Store Views')) ?></strong></td>
            <td class="emph"><strong><?php echo $block->escapeHtml($block->formatCurrency($block->getTotals()->getBaseLifetime())) ?></strong></td>
            <td class="emph last"><strong><?php echo $block->escapeHtml($block->formatCurrency($block->getTotals()->getAvgsale())) ?></strong></td>
        </tr>
        </tfoot>
        <?php endif; ?>
        <?php if ($block->getRows()): ?>
        <tbody>
            <?php $_i = 0; ?>
            <?php foreach ($block->getRows() as $_websiteId => $_groups): ?>
            <?php $_websiteRow = false; ?>
            <?php foreach ($_groups as $_groupId => $_stores): ?>
                <?php $_groupRow = false; ?>
                <?php foreach ($_stores as $_row): ?>
                    <?php if (!$singleStoreMode): ?>
                        <?php if ($_row->getStoreId() == 0): ?>
                        <td colspan="3"><?php echo $block->escapeHtml($_row->getStoreName()) ?></td>
                            <?php else: ?>
                    <tr<?php echo($_i++ % 2 ? ' class="even"' : '') ?>>
                            <?php if (!$_websiteRow): ?>
                                <td rowspan="<?php echo $block->escapeHtmlAttr($block->getWebsiteCount($_websiteId)) ?>"><?php echo $block->escapeHtml($_row->getWebsiteName()) ?></td>
                                <?php $_websiteRow = true; ?>
                                <?php endif; ?>
                            <?php if (!$_groupRow): ?>
                                <td rowspan="<?php echo count($_stores) ?>"><?php echo $block->escapeHtml($_row->getGroupName()) ?></td>
                                <?php $_groupRow = true; ?>
                                <?php endif; ?>
                            <td><?php echo $block->escapeHtml($_row->getStoreName()) ?></td>
                            <?php endif; ?>
                        <?php else: ?>
                    <tr>
                        <?php endif; ?>
                    <td><?php echo $block->escapeHtml($block->formatCurrency($_row->getLifetime(), $_row->getWebsiteId())) ?></td>
                    <td><?php echo $block->escapeHtml($block->formatCurrency($_row->getAvgsale(), $_row->getWebsiteId())) ?></td>
                    </tr>
                    <?php endforeach; ?>
                <?php endforeach; ?>
            <?php endforeach; ?>
        </tbody>
        <?php else: ?>
        <tbody>
        <tr class="hidden"><td colspan="<?php /* @noEscape */ echo $singleStoreMode ? 2 : 5; ?>"></td></tr>
        </tbody>
        <?php endif; ?>
    </table>
</div>
